package com.example.javabasic.bean.demo1;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/** 测试bpp  bean工厂后置处理器
 * @description
 * @Author Lin FuYuan
e 2020/12/21
 */
@Component
public class TestBeanPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
        //从 factory中的 map中根据bean名称获取bean的定义
        BeanDefinition bean = factory.getBeanDefinition("user");
        Object user = factory.getBean("user");
        System.out.println("用户信息:"+user);
        //此处可以对这个  bean 进行修改, 比如强转,注册bean, 或者用其他类替代这个bean;
        String scope = bean.getScope();
        System.out.println(scope);

    }


}
